package com.coolwen.service;

import com.coolwen.dao.UserMapper;
import com.coolwen.entity.User;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by user on 2016/4/25.
 */

@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User getUserById(String id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<User> selectAllUser() {
        return userMapper.selectAllUser();
    }


    @Override
    public int insert(User userInfo) {
        int result = userMapper.insert(userInfo);
//        System.out.println(result);
        return result;
    }

    @Override
    public int updateByPrimaryKeySelective(User record) {
        return userMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int deleteByPrimaryKey(Long userId) {
        return userMapper.deleteByPrimaryKey(userId);
    }

    @Override
    public PageInfo<User> queryByPage(String userName, Integer pageNo, Integer pageSize) {
 //       pageNo = pageNo == null?1:pageNo;
 //       pageSize = pageSize == null?5:pageSize;
        PageHelper.startPage(pageNo, pageSize);  //startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
        List<User> users = userMapper.selectUserByUserName(userName);
        PageInfo<User> userPageInfo=new PageInfo<User>(users);
        return userPageInfo;

    }


//    public UserMapper getUserMapper() {
//        return userMapper;
//    }
//    @Autowired
//    public void setUserMapper(UserMapper userMapper) {
//        this.userMapper = userMapper;
//    }
}
